<template>
<div class="content-center">
  <div class="content-cotainer border-box">
    <div class="content-breadcrumb">
      <el-breadcrumb separator="/" class="breadcrumb">
        <el-breadcrumb-item :to="{ path: '/' }">审计作业</el-breadcrumb-item>
        <el-breadcrumb-item>新建审计取证单</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="audit-content">
      <div class="centent-title">
        <span>{{title}}</span>
      </div>
      <!-- 页面内容 -->
      <div class="centent-inner" style="padding:15px;">
        <el-form :model="dataForm" label-width="140px" size="small">
          <el-row>
            <el-button type="primary" size="small" icon="el-icon-check" @click="save">保存</el-button>
            <el-button type="info" size="small" icon="el-icon-bottom">导出</el-button>
            <el-button type="primary" size="small" icon="el-icon-paperclip" style="float:right;">打印</el-button>
            <el-button type="primary" size="small" icon="el-icon-paperclip" style="float:right;" @click="showEvidenceData">关联审计证据</el-button>

          </el-row>
          <br>
          <el-row>
            <el-col :span="8">
              <el-form-item label="取证单名称：">
                <el-input v-model="dataForm.auditEvdblNm" placeholder="请选择取证单名称："></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审计人员：">
                <el-select v-model="dataForm.auditorNms" placeholder="请输入审计人员">
                  <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建日期：">
                <el-date-picker v-model="dataForm.createDt"  placeholder="请选择创建日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" size="small"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="被审计单位和个人：">
                <el-input v-model="dataForm.byauditInstNm" placeholder="请输入被审计单位和个人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="审计事项：">
                <el-select v-model="dataForm.auditItemDsc" placeholder="请选择审计事项" size="small">
                  <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="细分审计事项：">
                <el-input v-model="dataForm.auditItemDsc" placeholder="请输入细分审计事项"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="审计事项摘要：">
                <el-input v-model="dataForm.auditorMatterDsc" type="textarea" :rows="5" placeholder="请输入审计事项摘要："></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-button size="small">预览附件</el-button>
            <el-button size="small">从资料树引入附件</el-button>
            <el-button size="small">从系统引入附件</el-button>
            <el-button size="small">删除附件</el-button>
          </el-row>
          <el-row style="margin-top: 20px;">
            <el-table :data="data" style="width: 100%;border-radius:1px;border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-left-radius: 6px;border-bottom-right-radius: 6px;" border>
              <el-table-column type="selection" width="50" align="center"></el-table-column>
              <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
              <el-table-column prop="b" label="附件名称" align="center"></el-table-column>
              <el-table-column prop="c" label="上传人" align="center"></el-table-column>
              <el-table-column prop="e" label="上传日期" align="center"></el-table-column>
            </el-table>
          </el-row>
          <br>
          <el-row>
            <el-button size="small">预览电子取证单</el-button>
            <el-button size="small">从系统引入电子取证单</el-button>
            <el-button size="small">删除附件</el-button>
          </el-row>
          <el-row style="margin-top: 20px;">
            <el-table :data="data" style="width: 100%;border-radius:1px;border-top-left-radius: 6px;border-top-right-radius: 6px;border-bottom-left-radius: 6px;border-bottom-right-radius: 6px;" border>
              <el-table-column type="selection" width="50" align="center"></el-table-column>
              <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
              <el-table-column prop="b" label="附件名称" align="center"></el-table-column>
              <el-table-column prop="c" label="上传人" align="center"></el-table-column>
              <el-table-column prop="e" label="上传日期" align="center"></el-table-column>
            </el-table>
          </el-row>
          <!--<el-pagination style="margin-top: 10px;" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="10" layout="total, sizes, prev, pager, next, jumper" :total="40">
          </el-pagination>-->
        </el-form>

        <el-dialog :visible.sync="dialogAuditTableVisible" title="审计证据" width="80%" top="10vh">
          <el-table :data="auditTableData"  @selection-change="selsChange" stripe>
            <el-table-column type="selection"></el-table-column>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="审计证据名称" prop="auditPrfNm" align="center">
            </el-table-column>
            <el-table-column prop="prfDesc" label="审计证据概述">
            </el-table-column>
            <el-table-column prop="fileName" label="附件名称">
            </el-table-column>
            <el-table-column prop="createDt" label="编制日期"></el-table-column>
            <el-table-column prop="writerNm" label="编制人">
            </el-table-column>
            <el-table-column prop="lcsCd" label="状态"></el-table-column>
            <!--<el-table-column prop="draft" label="已关联审计底稿">
              <template slot-scope="scope">
                <el-button type="text" @click="selectDraft()">{{scope.row.draft}}</el-button>
              </template>
            </el-table-column>-->
          </el-table>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogAuditTableVisible = false">取消</el-button>
            <el-button  type="primary" @click="relationEvidence()">确定</el-button>
          </div>
        </el-dialog>

      </div>
    </div>
  </div>
</div>
</template>

<script>
  import evidenceservice from '@/api/auditoperationApi/evidenceservice'
  import axios from 'axios'
export default {
  data() {
    return {
      sss: '',
      dialogAuditTableVisible: false,
      auditTableData: [],
      selectedlist: [],
      sels: [],
      // 新增编辑界面数据
      dataForm: {
        auditEvdblId: '',
        auditEvdblNm: '',
        auditorNms: '',
        createDt: '',
        byauditInstNm: '',
        auditItemDsc: '',
        auditorMatterDsc: ''
      },
      options: [{
        value: '1',
        label: '事项1'
      }, {
        value: '2',
        label: '事项2'
      }, {
        value: '3',
        label: '事项3'
      }],
      model: {
        event: ''
      },
      data: [{
        b: '某某公司税务缴纳',
        c: '预算编制不细化',
        d: '张毅',
        e: '2019-8-16'
      }],
      currentPage: 1,
      title: '新建审计取证单'
    }
  },
  mounted() {
    this.getData();
  },
  methods: {

    showEvidenceData(){
      this.dialogAuditTableVisible = true;
      let info = {
        nodeId :1
      }
      axios.post(evidenceservice.baseUrl +'/evidence/queryEvidence', info).then((response) => {
        this.auditTableData = response.data
      }).catch((response) => {
        console.log(response)
      })
    },
    relationEvidence(){
      if(this.sels.length > 0){
        this.dialogAuditTableVisible = false;
      }else{
        this.$message.warning('请勾选数据')
      }
    },
    selsChange (val) {
      this.sels = val
    },
    selectedchange (val) {
      this.selectedlist = val
    },
    save() {
      //let params = this.dataForm;
      //let params2 = this.selectedlist;
      let params = {};
      params.evbl = this.dataForm;
      params.prfList = this.sels;
      if(params.evbl.auditEvdblId){
        axios.post(evidenceservice.baseUrl +'/evidenceAuditEvdBl/update', params)
                .then(response => {
                  this.$message({
                    type: 'success',
                    message: response.data.obj
                  });
                  this.$router.push({
                    path: '/auditOperationPage/auditevidencedocket'
                  })
                }, err => {
                  //reject(err);
                }).catch((error) => {
                  //reject(error)
                })
      }else{
        axios.post(evidenceservice.baseUrl +'/evidenceAuditEvdBl/add', params)
                .then(response => {
                  this.$message({
                    type: 'success',
                    message: response.data.obj
                  });
                  this.$router.push({
                    path: '/auditOperationPage/auditevidencedocket'
                  })
                }, err => {
                  //reject(err);
                }).catch((error) => {
                  //reject(error)
                })
      }
    },
    getData () {
      let auditEvdblId= this.$route.query.auditEvdblId;
      if(auditEvdblId != null && auditEvdblId != ''){
        axios.post(evidenceservice.baseUrl +'/evidenceAuditEvdBl/findAuditEvdBlList', {auditEvdblId:auditEvdblId})
                .then(response => {
                  //resolve(response);
                  this.dataForm = response.data.obj[0];
                }, err => {
                  //reject(err);
                })
                .catch((error) => {
                  //reject(error)
                })
      }else{
        this.dataForm.createDt = evidenceservice.getNowFormatDate();
      }
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  }
}
</script>

<style lang="less" scoped>
.content-cotainer {
  padding: 0 20px 20px 20px;
  height: 100%;
}
</style>
